﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Alos.Common;
using Alos.Entity;
using Alos.IService;
using Newtonsoft.Json;
using System.Threading.Tasks;

namespace Alos.LanClass.Api
{
    /// <summary>
    /// 学生提交记录表（客观题）
    /// </summary>
    public class ReObjectiveQuestionController : ApiController
    {
        IReObjectiveQuestionService ReObjectiveQuestionService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_ReObjectiveQuestionService"></param>
        public ReObjectiveQuestionController(IReObjectiveQuestionService _ReObjectiveQuestionService)
        {          
            ReObjectiveQuestionService = _ReObjectiveQuestionService;         
        }
        /// <summary>
        /// 添加学生提交记录(客观题)
        /// <param name="data">学生提交客观题</param>
        /// </summary>
        [HttpPost]
        [Route("api/ReObjectiveQuestion/CreateReObjectiveQuestion")]
        public JsonRtn<dynamic> CreateReObjectiveQuestion([FromBody]dynamic data)
        {           
            List<ReObjectiveQuestion> reObjectiveQuestions = JsonConvert.DeserializeObject<List<ReObjectiveQuestion>>(data);
            var jsRtn = new JsonRtn<dynamic>();
            jsRtn.message = ReObjectiveQuestionService.CreateKeGuan(reObjectiveQuestions) ? "true" : "false";
            return jsRtn;    
        }
        /// <summary>
        /// 统计学生提交记录（客观题）
        /// </summary>
        /// <param name="ArrangeID">发布记录表编号</param>       
        /// <returns>该课程学生提交记录及习题</returns>
        [HttpPost]
        [Route("api/ReObjectiveQuestion/GetReObjectiveQuestionByArrangeID")]
        public async Task<JsonRtn<List<dynamic>>> GetReObjectiveQuestionByArrangeID([FromBody]int ArrangeID)
        {
            var jsRtn = new JsonRtn<List<dynamic>>();
            jsRtn.data = await Task.Factory.StartNew(id =>
            {
                return ReObjectiveQuestionService.GetReObjectiveQuestionByArrangeID((int)id).ToList();
            }, ArrangeID);
            return jsRtn;
        }
    }
}
